<?php
//no direct access
defined('_JEXEC') or die( 'Restricted access' );
//import the JController Class
jimport( 'joomla.application.component.controller' );

class NvController extends JController {


	function display(){

		$viewName = JRequest::getVar('view',0);
		if ( ! JRequest::getCmd( 'format' ) ) {
			JRequest::setVar('format', 'html' );
		}

		if ($viewName == 'home' ){


		//get view name and type
		$document =& JFactory::getDocument();
		
		//initial variable for home View
		$viewName = 'home';
		$kota = 'jakarta';
		
		$viewType = $document->getType();
		$view  = $this->getView($viewName,$viewType);

		//get all module at once
    	$modelVideo = $this->getModel('youtube');
    	$modelPic = $this->getModel('flickr');
    	$modelEvent = $this->getModel('event');
    	$modelWeather = $this->getModel('weather');
    	$modelResto = $this->getModel('restoran');
    	$modelBlogs = $this->getModel('blogs');
    	$modelHotel = $this->getModel('hotel');

    	//get data array from youtube model
    	$dataVid = $modelVideo->getVideoList('wisata indonesia',3);
    	$dataPic= $modelPic->getPicture('indonesia',4);
    	$dataEvent = $modelEvent->getEvent('indonesia',1);
    	$dataWeather = $modelWeather->getWeather($kota);
		$dataRestoran = $modelResto->getRestoran($kota);
		$dataBlog = $modelBlogs->getBlogMashup($kota,2);
		$dataHotel = $modelHotel->getHotel($kota);

    	$view->assignRef('datavid',$dataVid);
    	$view->assignRef('datapic',$dataPic);
    	$view->assignRef('dataevent',$dataEvent);
    	$view->assignRef('dataweather',$dataWeather);
    	$view->assignRef('xml',$dataRestoran);
    	$view->assignRef('kota',$kota);
    	$view->assignRef('datablog',$dataBlog);
    	$view->assignRef('datahotel',$dataHotel);

    	$view->display();

		}else if($viewName == 'objek' ){
		
		//get object name from request parameter
		$namaobjek = JRequest::getVar('nama',0);
			
			
		//load search model
		$modelSearch = $this->getModel('search');
		//get search result 
    	$dataObjek = $modelSearch->searchObject($namaobjek);
		
		
	
	
		foreach ($dataObjek as $objek){
	    	$objekName = $objek->name;
			$objekKota = $objek->nama_kota;
			$objekLat = $objek->latitude;
			$objekLong = $objek->longitude;
			$objekKet =  $objek->keterangan;
		}
		
		
		//get view name and type
		$document =& JFactory::getDocument();

		$viewName = 'objek';
		$viewType = $document->getType();
		$view  = $this->getView($viewName,$viewType);

		//get all module at once
    	$modelVideo = $this->getModel('youtube');
    	$modelPic = $this->getModel('flickr');
    	$modelEvent = $this->getModel('event');
    	$modelWeather = $this->getModel('weather');

    	
    	//get data array from youtube model
    	$dataVid = $modelVideo->getVideoList($objekName,10);
    	$dataPic= $modelPic->getPicture($objekName,40);
    	$dataEvent = $modelEvent->getEvent($objekKota,10);
    	$dataWeather = $modelWeather->getWeather($objekKota);


    	
    	$view->assignRef('datavid',$dataVid);
    	$view->assignRef('datapic',$dataPic);
    	$view->assignRef('dataevent',$dataEvent);
    	$view->assignRef('dataweather',$dataWeather);
    	$view->assignRef('dataobjek',$dataObjek);
			
	    $view->display();

		}else{

			parent::display();
		}
	}

	function search()
	{
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
		
		$result = $this->getResult();
		$str = $this->getString();
		
		// Cek, Inputan kosong atau tidak
		if( $result && !empty($str) )
		{			
			//set variabel throw to views
			JRequest::setVar( 'result' , $result );
			JRequest::setVar( 'str' , $str );
			
		}//end of if not empty
		else
		{
			JRequest::setVar( 'result' , $result = false );
		}//end of else
		
		//get view name and type
		$document =& JFactory::getDocument();
		$viewName = JRequest::getVar('view');
		$viewType = $document->getType();
		$view  = $this->getView($viewName,$viewType);
		
		//action to view.html.php
    	$view->display();
		
	}//end of function search
	
	function getString()
	{
		return JRequest::getVar( 'objek_name' );
	}//end of function getString
	
	function getResult()
	{
		return JRequest::getVar( 'result' );
	}//end of function getResult

}
?>